<!DOCTYPE html>
<html>

<head>
<title>Facebook Login JavaScript Example</title>
<meta charset="UTF-8">
</head>
<body>
<script>
  // This is called with the results from from FB.getLoginStatus().
  function statusChangeCallback(response) {
    console.log('statusChangeCallback');
    console.log(response);

    if (response.status === 'connected') {
      // Logged into your app and Facebook.
      testAPI();
    } else if (response.status === 'not_authorized') {
      // The person is logged into Facebook, but not your app.
      document.getElementById('status').innerHTML = 'Please log ' +
        'into this app.';
    } else {
      // The person is not logged into Facebook, so we're not sure if
      // they are logged into this app or not.
      document.getElementById('status').innerHTML = 'Please log ' +
        'into Facebook.';
    }
  }

 
  function checkLoginState() {
    FB.getLoginStatus(function(response) {
      statusChangeCallback(response);
    });
  }

  window.fbAsyncInit = function() {
  FB.init({
    appId      : '1441103716137580',
    cookie     : true,  
    xfbml      : true,  
    version    : 'v2.0' 
  });


  FB.getLoginStatus(function(response) {
    statusChangeCallback(response);
  });

  };

  // Load the SDK asynchronously
  (function(d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) return;
        js = d.createElement(s); js.id = id;
        js.src = "//connect.facebook.net/en_US/sdk.js";
        fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));


  function testAPI() {
    console.log('Bienvenido Web Bolsa de Trabajo!  Fetching your information.... ');
    FB.api('/me', function(response) {
      console.log('Successful login for: '); 
      console.log('Nombre    : ' + response.name);
      console.log('Cumpleano : ' + response.birthday);
      console.log('Email     : ' + response.email);
      console.log('Genero    : ' + response.gender);
      console.log('Direccion : ' + response.hometown.name);
      
      for(ed in response.education) {
            var schoolName = response.education[ed].school.name;
            var schoolType = response.education[ed].type;
            console.log('Centro Estudios : ' + schoolName);
            console.log('Grado : ' + schoolType);
      }
      
      for(ed in response.work) {
            var employerName = response.work[ed].employer.name;
            var positionName = response.work[ed].position.name;
            console.log('Trabajos : ' + employerName);
            console.log('Puesto : ' + positionName);
      }

      document.getElementById('status').innerHTML =
        'Gracias por logging in, ' + response.name + '!';
    });
  }
</script>

<h3>Login App</h3>
<fb:login-button scope="public_profile,email,user_birthday,user_hometown,user_education_history,user_work_history"
                 onlogin="checkLoginState();">
                     
</fb:login-button>
<h3>Quienes usan el APP</h3>
<fb:login-button max_rows="3" size="medium" show_faces="true" auto_logout_link="false"></fb:login-button>

<div id="status"></div>

</body>
</html>
